package com.everest.tribalapp;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CheckBox;

public class Dering_Pengelola_1 extends Activity implements OnClickListener {

	private Button next;
	private Spinner dering_f1_ans_1;
	private Spinner dering_f1_ans_2;
	private Spinner dering_f1_ans_3;
	private Spinner dering_f1_ans_4;
	private EditText dering_f1_ans_5a;
	private EditText dering_f1_ans_5b;
	private EditText dering_f1_ans_5c;
	private EditText dering_f1_ans_6;
	private EditText dering_f1_ans_7;
	private EditText dering_f1_ans_8;
	private EditText dering_f1_ans_9;
	private TextView dering_f1_qes_1;
	private TextView dering_f1_qes_2;
	private TextView dering_f1_qes_3;
	private TextView dering_f1_qes_4;
	private TextView dering_f1_qes_5a;
	private TextView dering_f1_qes_5b;
	private TextView dering_f1_qes_5c;
	private String value;
	private int flag = 0;
	protected int id;
	protected String[] choice;
	protected String selectvalue;
	private CharSequence[] MSG_VALUES_6 = { "Telepon kabel","Warung telepon (Wartel) / Warsel", "Telepon seluler (HP)","Warung internet (Warnet)" };
	private CharSequence[] MSG_VALUES_7 = { "Telkomsel", "Indosat", "X L","Flexi", "Esia", "Three (3)", "Axis", "Fren", "Ceria", "Smart" };
	private CharSequence[] MSG_VALUES_8={"Perangkat tidak digunakan","Perangkat rusak","lainnya, Sebutkan"};
	private CharSequence[] MSG_VALUES_9 = { "Telkomsel", "Indosat", "X L","Flexi", "Esia", "Three (3)", "Axis", "Fren", "Ceria", "Smart" };
	private ArrayList<String> stringArrayList1;
	private ArrayList<String> stringArrayList2;
	private ArrayList<String> stringArrayList3;
	private ArrayList<String> stringArrayList11;
	private ArrayList<String> stringArrayList12;
	private String[] selectid;
	private String[] selectname;
	private String[] select_district;
	private String[] select_sub;
	private String[] select_desa;
	private Spinner s;
	private Spinner s1;
	private Spinner s2;
	private Spinner s3;
	private TextView dering_f1_qes_6;
	private TextView dering_f1_qes_7;
	private TextView dering_f1_qes_8;
	private TextView dering_f1_qes_9;
	protected String selectetdVal;
	protected boolean[] selectVal6 = { false, false, false, false };
	protected boolean[] selectVal7 = { false, false, false, false, false,false, false, false, false, false };
	protected boolean[] selectVal9 = { false, false, false, false, false,false, false, false, false, false };
	private CheckBox checkBox_6a1;
	private CheckBox checkBox_6b1;
	private CheckBox checkBox_6c1;
	private CheckBox checkBox_6d1;
	private CheckBox checkBox_7a1;
	private CheckBox checkBox_7b1;
	private CheckBox checkBox_7c1;
	private CheckBox checkBox_7d1;
	private CheckBox checkBox_7e1;
	private CheckBox checkBox_7f1;
	private CheckBox checkBox_7g1;
	private CheckBox checkBox_7h1;
	private CheckBox checkBox_7i1;
	private CheckBox checkBox_7j1;
	private CheckBox checkBox_9a1;
	private CheckBox checkBox_9b1;
	private CheckBox checkBox_9c1;
	private CheckBox checkBox_9d1;
	private CheckBox checkBox_9e1;
	private CheckBox checkBox_9f1;
	private CheckBox checkBox_9g1;
	private CheckBox checkBox_9h1;
	private CheckBox checkBox_9i1;
	private CheckBox checkBox_9j1;

	@Override
	public void onBackPressed() {
		Intent intent = new Intent(getApplicationContext(), Add1.class);
		startActivity(intent);
		Dering_Pengelola_1.this.finish();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Dering_Pengelola_1.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dering_pengelola_1);

		initialization();
		Boolean a;
		a = isOnline();
		if (a) {
			new Check().execute();
		} else {

			ArrayAdapter adapter = new ArrayAdapter(Dering_Pengelola_1.this,
					android.R.layout.simple_spinner_item, Global.province);
			s.setAdapter(adapter);
			ArrayAdapter adapter1 = new ArrayAdapter(Dering_Pengelola_1.this,
					android.R.layout.simple_spinner_item, Global.district);
			s1.setAdapter(adapter1);
			ArrayAdapter adapter2 = new ArrayAdapter(Dering_Pengelola_1.this,
					android.R.layout.simple_spinner_item, Global.subdistrict);
			s2.setAdapter(adapter2);
			ArrayAdapter adapter3 = new ArrayAdapter(Dering_Pengelola_1.this,
					android.R.layout.simple_spinner_item, Global.desa);
			s3.setAdapter(adapter3);

		}
		next.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in = new Intent(getApplicationContext(),
						Dering_Pengelola_2.class);
				startActivity(in);
				Dering_Pengelola_1.this.finish();
			}
		});
	}

	private void initialization() {
		dering_f1_qes_1 = (TextView) findViewById(R.id.dering_f1_qes_1);
		dering_f1_qes_2 = (TextView) findViewById(R.id.dering_f1_qes_2);
		dering_f1_qes_3 = (TextView) findViewById(R.id.dering_f1_qes_3);
		dering_f1_qes_4 = (TextView) findViewById(R.id.dering_f1_qes_4);
		dering_f1_qes_5a = (TextView) findViewById(R.id.dering_f1_qes_5a);
		dering_f1_qes_5b = (TextView) findViewById(R.id.dering_f1_qes_5b);
		dering_f1_qes_5c = (TextView) findViewById(R.id.dering_f1_qes_5c);
		dering_f1_qes_6 =  (TextView) findViewById(R.id.dering_f1_qes_6);
		dering_f1_qes_7 =  (TextView) findViewById(R.id.dering_f1_qes_7);
		dering_f1_qes_8 =  (TextView) findViewById(R.id.dering_f1_qes_8);
		dering_f1_qes_9 =  (TextView) findViewById(R.id.dering_f1_qes_9);
		dering_f1_ans_1 = (Spinner) findViewById(R.id.dering_f1_ans_provinsi);
		dering_f1_ans_2 = (Spinner) findViewById(R.id.dering_f1_ans_kubupaten);
		dering_f1_ans_3 = (Spinner) findViewById(R.id.dering_f1_ans_kecamaten);
		dering_f1_ans_4 = (Spinner) findViewById(R.id.dering_f1_ans_desa);
		dering_f1_ans_5a = (EditText) findViewById(R.id.dering_f1_ans_kpu1);
		dering_f1_ans_5b = (EditText) findViewById(R.id.dering_f1_ans_kpu2);
		dering_f1_ans_5c = (EditText) findViewById(R.id.dering_f1_ans_catatan);
		dering_f1_ans_8 = (EditText) findViewById(R.id.dering_f1_ans_8);
		checkBox_6a1=(CheckBox)findViewById(R.id.checkBox_6a1);
		checkBox_6b1=(CheckBox)findViewById(R.id.checkBox_6b1);
		checkBox_6c1=(CheckBox)findViewById(R.id.checkBox_6c1);
		checkBox_6d1=(CheckBox)findViewById(R.id.checkBox_6d1);
		checkBox_7a1=(CheckBox)findViewById(R.id.checkBox_7a1);
		checkBox_7b1=(CheckBox)findViewById(R.id.checkBox_7b1);
		checkBox_7c1=(CheckBox)findViewById(R.id.checkBox_7c1);
		checkBox_7d1=(CheckBox)findViewById(R.id.checkBox_7d1);
		checkBox_7e1=(CheckBox)findViewById(R.id.checkBox_7e1);
		checkBox_7f1=(CheckBox)findViewById(R.id.checkBox_7f1);
		checkBox_7g1=(CheckBox)findViewById(R.id.checkBox_7g1);
		checkBox_7h1=(CheckBox)findViewById(R.id.checkBox_7h1);
		checkBox_7i1=(CheckBox)findViewById(R.id.checkBox_7i1);
		checkBox_7j1=(CheckBox)findViewById(R.id.checkBox_7j1);
		checkBox_9a1=(CheckBox)findViewById(R.id.checkBox_9a1);
		checkBox_9b1=(CheckBox)findViewById(R.id.checkBox_9b1);
		checkBox_9c1=(CheckBox)findViewById(R.id.checkBox_9c1);
		checkBox_9d1=(CheckBox)findViewById(R.id.checkBox_9d1);
		checkBox_9e1=(CheckBox)findViewById(R.id.checkBox_9e1);
		checkBox_9f1=(CheckBox)findViewById(R.id.checkBox_9f1);
		checkBox_9g1=(CheckBox)findViewById(R.id.checkBox_9g1);
		checkBox_9h1=(CheckBox)findViewById(R.id.checkBox_9h1);
		checkBox_9i1=(CheckBox)findViewById(R.id.checkBox_9i1);
		checkBox_9j1=(CheckBox)findViewById(R.id.checkBox_9j1);
		/*s = (Spinner) findViewById(R.id.dering_f1_ans_provinsi);
		s1 = (Spinner) findViewById(R.id.dering_f1_ans_kubupaten);
		s2 = (Spinner) findViewById(R.id.dering_f1_ans_kecamaten);
		s3 = (Spinner) findViewById(R.id.dering_f1_ans_desa);*/

		next = (Button) findViewById(R.id.next);
		dering_f1_qes_1.setOnClickListener(this);
		dering_f1_qes_2.setOnClickListener(this);
		dering_f1_qes_3.setOnClickListener(this);
		dering_f1_qes_4.setOnClickListener(this);
		dering_f1_qes_5a.setOnClickListener(this);
		dering_f1_qes_5b.setOnClickListener(this);
		dering_f1_qes_5c.setOnClickListener(this);
		dering_f1_qes_6.setOnClickListener(this);
		dering_f1_qes_7.setOnClickListener(this);
		dering_f1_qes_8.setOnClickListener(this);
		dering_f1_qes_9.setOnClickListener(this);
		dering_f1_ans_8.setOnClickListener(this);
		checkBox_6a1.setOnClickListener(this);
		checkBox_6b1.setOnClickListener(this);
		checkBox_6c1.setOnClickListener(this);
		checkBox_6d1.setOnClickListener(this);
		checkBox_7a1.setOnClickListener(this);
		checkBox_7b1.setOnClickListener(this);
		checkBox_7c1.setOnClickListener(this);
		checkBox_7d1.setOnClickListener(this);
		checkBox_7e1.setOnClickListener(this);
		checkBox_7f1.setOnClickListener(this);
		checkBox_7g1.setOnClickListener(this);
		checkBox_7h1.setOnClickListener(this);
		checkBox_7i1.setOnClickListener(this);
		checkBox_7j1.setOnClickListener(this);
		checkBox_9a1.setOnClickListener(this);
		checkBox_9b1.setOnClickListener(this);
		checkBox_9c1.setOnClickListener(this);
		checkBox_9d1.setOnClickListener(this);
		checkBox_9e1.setOnClickListener(this);
		checkBox_9f1.setOnClickListener(this);
		checkBox_9g1.setOnClickListener(this);
		checkBox_9h1.setOnClickListener(this);
		checkBox_9i1.setOnClickListener(this);
		checkBox_9j1.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == dering_f1_qes_1.getId()) {
			value = getResources().getString(R.string.dering_f1_qes_1);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_2.getId()) {
			value = getResources().getString(R.string.dering_f1_qes_2);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_3.getId()) {
			value = getResources().getString(R.string.dering_f1_qes_3);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_4.getId()) {
			value = getResources().getString(R.string.dering_f1_qes_4);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_5a.getId()) {
			value = getResources().getString(R.string.dering_peng_q1_5a);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_5b.getId()) {
			value = getResources().getString(R.string.dering_peng_q1_5b);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_5c.getId()) {
			value = getResources().getString(R.string.dering_peng_q1_5c);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_6.getId()) {
			value = getResources().getString(R.string.dering_peng_q1_6a);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_7.getId()) {
			value = getResources().getString(R.string.dering_peng_q1_7a);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_8.getId()) {
			value = getResources().getString(R.string.dering_peng_q1_8);
			toast_msg();
		} else if (v.getId() == dering_f1_qes_9.getId()) {
			value = getResources().getString(R.string.dering_peng_q1_9a);
			toast_msg();
		} else if (v.getId()== dering_f1_ans_8.getId()){
			msg_dering_f1_ans_8();
		} else if(v.getId()== checkBox_6a1.getId()){
			checkBox_6a1.setChecked(false);
			msg_dering_f1_ans_6();
		}
		else if(v.getId()==checkBox_6b1.getId())
		{
			checkBox_6b1.setChecked(false);
			msg_dering_f1_ans_6();
		}
		else if(v.getId()==checkBox_6c1.getId())
		{
			checkBox_6c1.setChecked(false);
			msg_dering_f1_ans_6();
		}
		else if(v.getId()==checkBox_6d1.getId())
		{
			checkBox_6d1.setChecked(false);
			msg_dering_f1_ans_6();
		} else if(v.getId()== checkBox_7a1.getId()){
			checkBox_7a1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7b1.getId())
		{
			checkBox_7b1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7c1.getId())
		{
			checkBox_7c1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7d1.getId())
		{
			checkBox_7d1.setChecked(false);
			msg_dering_f1_ans_7();
		} 
		else if(v.getId()== checkBox_7e1.getId()){
			checkBox_7e1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7f1.getId())
		{
			checkBox_7f1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7g1.getId())
		{
			checkBox_7g1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7h1.getId())
		{
			checkBox_7h1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7i1.getId())
		{
			checkBox_7g1.setChecked(false);
			msg_dering_f1_ans_7();
		}
		else if(v.getId()==checkBox_7j1.getId())
		{
			checkBox_7h1.setChecked(false);
			msg_dering_f1_ans_7();
		} else if(v.getId()== checkBox_9a1.getId()){
			checkBox_9a1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9b1.getId())
		{
			checkBox_9b1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9c1.getId())
		{
			checkBox_9c1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9d1.getId())
		{
			checkBox_9d1.setChecked(false);
			msg_dering_f1_ans_9();
		} 
		else if(v.getId()== checkBox_9e1.getId()){
			checkBox_9e1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9f1.getId())
		{
			checkBox_9f1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9g1.getId())
		{
			checkBox_9g1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9h1.getId())
		{
			checkBox_9h1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9i1.getId())
		{
			checkBox_9g1.setChecked(false);
			msg_dering_f1_ans_9();
		}
		else if(v.getId()==checkBox_9j1.getId())
		{
			checkBox_9h1.setChecked(false);
			msg_dering_f1_ans_9();
		}

	}

	public void toast_msg() {
		LayoutInflater inflater = getLayoutInflater();

		View layout = inflater.inflate(R.layout.custom_toast,
				(ViewGroup) findViewById(R.id.custom_toast_layout_id));
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(value);
		Toast toast = new Toast(getApplicationContext());
		toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(layout);
		toast.show();
	}
	
	private void msg_dering_f1_ans_8() {
	     Builder builder = new AlertDialog.Builder(this);
	     builder.setTitle("Select");
	     builder.setSingleChoiceItems(MSG_VALUES_8, -1, new DialogInterface.OnClickListener() {
	       

		@Override
	       public void onClick(DialogInterface dialog, int which) {
			 dering_f1_ans_8.setText(""+(which+1));
	         dialog.dismiss();
	         
	       }
	     });
	     builder.setNegativeButton("cancel",
	         new DialogInterface.OnClickListener() {
	           @Override
	           public void onClick(DialogInterface dialog, int which) {
	             dialog.dismiss();
	           }
	         });
	     AlertDialog alert = builder.create();
	     alert.show();
	   }
	private void msg_dering_f1_ans_6()
	   {
		     Builder builder = new AlertDialog.Builder(this);
		     builder.setTitle("Answer");
		     builder.setMultiChoiceItems(MSG_VALUES_6, selectVal6,
		         new DialogInterface.OnMultiChoiceClickListener()
		     {
		           @Override
		           public void onClick(DialogInterface dialog, int which,
		               boolean isChecked) 
		           {
		             selectVal6[which] = isChecked;
		           }
		         });
		     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
		       @Override
		       public void onClick(DialogInterface dialog, int which) {
		         for (int i = 0; i <MSG_VALUES_6.length; i++) 
		         {
		           if (selectVal6[i]) 
		           {
		              if(i==0)
		 				{
		            	 
		            	  checkBox_6a1.setChecked(true);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_6b1.setChecked(true);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_6c1.setChecked(true);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_6d1.setChecked(true);
		 				}
		           }
		           else
		           {
		        	   if(i==0)
		 				{
		            	 
		        		   checkBox_6a1.setChecked(false);
	 					}
		 				else if(i==1)
		 				{
		 					checkBox_6b1.setChecked(false);
		 				}
		 				else if(i==2)
		 				{
		 					checkBox_6c1.setChecked(false);
		 				}
		 				else if(i==3)
		 				{
		 					checkBox_6d1.setChecked(false);
		 				}
		 				
		           }
		         }
		        }
		     });
		     builder.setNegativeButton("cancel",
		         new DialogInterface.OnClickListener() {
		           @Override
		           public void onClick(DialogInterface dialog, int which) {
		             dialog.dismiss();
		           }
		         });
		     AlertDialog alert = builder.create();
		     alert.show();
		   } 
	
			private void msg_dering_f1_ans_7()
		   {
			     Builder builder = new AlertDialog.Builder(this);
			     builder.setTitle("Answer");
			     builder.setMultiChoiceItems(MSG_VALUES_7, selectVal7,
			         new DialogInterface.OnMultiChoiceClickListener()
			     {
			           @Override
			           public void onClick(DialogInterface dialog, int which,
			               boolean isChecked) 
			           {
			             selectVal7[which] = isChecked;
			           }
			         });
			     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
			       @Override
			       public void onClick(DialogInterface dialog, int which) {
			         for (int i = 0; i <MSG_VALUES_7.length; i++) 
			         {
			           if (selectVal7[i]) 
			           {
			              if(i==0)
			 				{
			            	 
			            	  checkBox_7a1.setChecked(true);
		 					}
			 				else if(i==1)
			 				{
			 					checkBox_7b1.setChecked(true);
			 				}
			 				else if(i==2)
			 				{
			 					checkBox_7c1.setChecked(true);
			 				}
			 				else if(i==3)
			 				{
			 					checkBox_7d1.setChecked(true);
			 				}
			 				else if(i==4)
			 				{
			 					checkBox_7e1.setChecked(true);
			 				}
			 				else if(i==5)
			 				{
			 					checkBox_7f1.setChecked(true);
			 				}
			 				else if(i==6)
			 				{
			 					checkBox_7g1.setChecked(true);
			 				}
			 				else if(i==7)
			 				{
			 					checkBox_7h1.setChecked(true);
			 				}
			 				else if(i==8)
			 				{
			 					checkBox_7i1.setChecked(true);
			 				}
			 				else if(i==9)
			 				{
			 					checkBox_7j1.setChecked(true);
			 				}
			           }
			           else
			           {
			        	   if(i==0)
			 				{
			            	 
			        		   checkBox_7a1.setChecked(false);
		 					}
			 				else if(i==1)
			 				{
			 					checkBox_7b1.setChecked(false);
			 				}
			 				else if(i==2)
			 				{
			 					checkBox_7c1.setChecked(false);
			 				}
			 				else if(i==3)
			 				{
			 					checkBox_7d1.setChecked(false);
			 				}
			 				else if(i==4)
			 				{
			 					checkBox_7e1.setChecked(false);
			 				}
			 				else if(i==5)
			 				{
			 					checkBox_7f1.setChecked(false);
			 				}
			 				else if(i==6)
			 				{
			 					checkBox_7g1.setChecked(false);
			 				}
			 				else if(i==7)
			 				{
			 					checkBox_7h1.setChecked(false);
			 				}
			 				else if(i==8)
			 				{
			 					checkBox_7i1.setChecked(false);
			 				}
			 				else if(i==9)
			 				{
			 					checkBox_7j1.setChecked(false);
			 				}
			 				
			           }
			         }
			        }
			     });
			     builder.setNegativeButton("cancel",
			         new DialogInterface.OnClickListener() {
			           @Override
			           public void onClick(DialogInterface dialog, int which) {
			             dialog.dismiss();
			           }
			         });
			     AlertDialog alert = builder.create();
			     alert.show();
			   }
			
			private void msg_dering_f1_ans_9()
			   {
				     Builder builder = new AlertDialog.Builder(this);
				     builder.setTitle("Answer");
				     builder.setMultiChoiceItems(MSG_VALUES_9, selectVal9,
				         new DialogInterface.OnMultiChoiceClickListener()
				     {
				           @Override
				           public void onClick(DialogInterface dialog, int which,
				               boolean isChecked) 
				           {
				             selectVal9[which] = isChecked;
				           }
				         });
				     builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
				       @Override
				       public void onClick(DialogInterface dialog, int which) {
				         for (int i = 0; i <MSG_VALUES_9.length; i++) 
				         {
				           if (selectVal9[i]) 
				           {
				              if(i==0)
				 				{
				            	 
				            	  checkBox_9a1.setChecked(true);
			 					}
				 				else if(i==1)
				 				{
				 					checkBox_9b1.setChecked(true);
				 				}
				 				else if(i==2)
				 				{
				 					checkBox_9c1.setChecked(true);
				 				}
				 				else if(i==3)
				 				{
				 					checkBox_9d1.setChecked(true);
				 				}
				 				else if(i==4)
				 				{
				 					checkBox_9e1.setChecked(true);
				 				}
				 				else if(i==5)
				 				{
				 					checkBox_9f1.setChecked(true);
				 				}
				 				else if(i==6)
				 				{
				 					checkBox_9g1.setChecked(true);
				 				}
				 				else if(i==7)
				 				{
				 					checkBox_9h1.setChecked(true);
				 				}
				 				else if(i==8)
				 				{
				 					checkBox_9i1.setChecked(true);
				 				}
				 				else if(i==9)
				 				{
				 					checkBox_9j1.setChecked(true);
				 				}
				           }
				           else
				           {
				        	   if(i==0)
				 				{
				            	 
				        		   checkBox_9a1.setChecked(false);
			 					}
				 				else if(i==1)
				 				{
				 					checkBox_9b1.setChecked(false);
				 				}
				 				else if(i==2)
				 				{
				 					checkBox_9c1.setChecked(false);
				 				}
				 				else if(i==3)
				 				{
				 					checkBox_9d1.setChecked(false);
				 				}
				 				else if(i==4)
				 				{
				 					checkBox_9e1.setChecked(false);
				 				}
				 				else if(i==5)
				 				{
				 					checkBox_9f1.setChecked(false);
				 				}
				 				else if(i==6)
				 				{
				 					checkBox_9g1.setChecked(false);
				 				}
				 				else if(i==7)
				 				{
				 					checkBox_9h1.setChecked(false);
				 				}
				 				else if(i==8)
				 				{
				 					checkBox_9i1.setChecked(false);
				 				}
				 				else if(i==9)
				 				{
				 					checkBox_9j1.setChecked(false);
				 				}
				 				
				           }
				         }
				        }
				     });
				     builder.setNegativeButton("cancel",
				         new DialogInterface.OnClickListener() {
				           @Override
				           public void onClick(DialogInterface dialog, int which) {
				             dialog.dismiss();
				           }
				         });
				     AlertDialog alert = builder.create();
				     alert.show();
				   }
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		SharedPreferences preferences = getSharedPreferences(
				"dering_f1_details", MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putString("1_5a", dering_f1_ans_5a.getText().toString().trim());
		editor.putString("1_5b", dering_f1_ans_5b.getText().toString().trim());
		editor.putString("1_5c", dering_f1_ans_5c.getText().toString().trim());
		editor.putString("1_8", dering_f1_ans_5a.getText().toString().trim());
		//editor.putString("1_1", s.getSelectedItem().toString().trim());
		//editor.putString("1_2", s1.getSelectedItem().toString().trim());
		//editor.putString("1_3", s2.getSelectedItem().toString().trim());
		//editor.putString("1_4", s3.getSelectedItem().toString().trim());
		editor.putBoolean("1_6a",checkBox_6a1.isChecked());
		editor.putBoolean("1_6b",checkBox_6b1.isChecked());
		editor.putBoolean("1_6c",checkBox_6c1.isChecked());
		editor.putBoolean("1_6d",checkBox_6d1.isChecked());
		editor.putBoolean("1_7a",checkBox_7a1.isChecked());
		editor.putBoolean("1_7b",checkBox_7b1.isChecked());
		editor.putBoolean("1_7c",checkBox_7c1.isChecked());
		editor.putBoolean("1_7d",checkBox_7d1.isChecked());
		editor.putBoolean("1_7e",checkBox_7e1.isChecked());
		editor.putBoolean("1_7f",checkBox_7f1.isChecked());
		editor.putBoolean("1_7g",checkBox_7g1.isChecked());
		editor.putBoolean("1_7h",checkBox_7h1.isChecked());
		editor.putBoolean("1_7i",checkBox_7i1.isChecked());
		editor.putBoolean("1_7j",checkBox_7j1.isChecked());
		editor.putBoolean("1_9a",checkBox_9a1.isChecked());
		editor.putBoolean("1_9b",checkBox_9b1.isChecked());
		editor.putBoolean("1_9c",checkBox_9c1.isChecked());
		editor.putBoolean("1_9d",checkBox_9d1.isChecked());
		editor.putBoolean("1_9e",checkBox_9e1.isChecked());
		editor.putBoolean("1_9f",checkBox_9f1.isChecked());
		editor.putBoolean("1_9g",checkBox_9g1.isChecked());
		editor.putBoolean("1_9h",checkBox_9h1.isChecked());
		editor.putBoolean("1_9i",checkBox_9i1.isChecked());
		editor.putBoolean("1_9j",checkBox_9j1.isChecked());

		editor.commit();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		SharedPreferences preferences = getSharedPreferences(
				"dering_f1_details", MODE_PRIVATE);
		dering_f1_ans_5a.setText(preferences.getString("1_5a", ""));
		dering_f1_ans_5b.setText(preferences.getString("1_5b", ""));
		dering_f1_ans_5c.setText(preferences.getString("1_5c", ""));
		checkBox_6a1.setChecked(preferences.getBoolean("1_6a",false));
		checkBox_6b1.setChecked(preferences.getBoolean("1_6b",false));
		checkBox_6c1.setChecked(preferences.getBoolean("1_6c",false));
		checkBox_6d1.setChecked(preferences.getBoolean("1_6d",false));
		checkBox_7a1.setChecked(preferences.getBoolean("1_7a",false));
		checkBox_7b1.setChecked(preferences.getBoolean("1_7b",false));
		checkBox_7c1.setChecked(preferences.getBoolean("1_7c",false));
		checkBox_7d1.setChecked(preferences.getBoolean("1_7d",false));
		checkBox_7e1.setChecked(preferences.getBoolean("1_7e",false));
		checkBox_7f1.setChecked(preferences.getBoolean("1_7f",false));
		checkBox_7g1.setChecked(preferences.getBoolean("1_7g",false));
		checkBox_7h1.setChecked(preferences.getBoolean("1_7h",false));
		checkBox_7i1.setChecked(preferences.getBoolean("1_7i",false));
		checkBox_7j1.setChecked(preferences.getBoolean("1_7j",false));
		checkBox_9a1.setChecked(preferences.getBoolean("1_9a",false));
		checkBox_9b1.setChecked(preferences.getBoolean("1_9b",false));
		checkBox_9c1.setChecked(preferences.getBoolean("1_9c",false));
		checkBox_9d1.setChecked(preferences.getBoolean("1_9d",false));
		checkBox_9e1.setChecked(preferences.getBoolean("1_9e",false));
		checkBox_9f1.setChecked(preferences.getBoolean("1_9f",false));
		checkBox_9g1.setChecked(preferences.getBoolean("1_9g",false));
		checkBox_9h1.setChecked(preferences.getBoolean("1_9h",false));
		checkBox_9i1.setChecked(preferences.getBoolean("1_9i",false));
		checkBox_9j1.setChecked(preferences.getBoolean("1_9j",false));
		

	}

	protected void province() {
		 /*
		boolean answer;
		answer = isOnline();
		System.out.println(answer);
		stringArrayList11 = new ArrayList<String>();
		stringArrayList12 = new ArrayList<String>();

		if (answer) {

			JSONObject json = JSONfunctions.getJSONfromURL(Global.province_url);
			try {
				JSONObject response1 = json.getJSONObject("response");
				response1.toString();
				JSONArray data = response1.getJSONArray("items");

				for (int i = 0; i < data.length(); i++) {

					JSONObject e = data.getJSONObject(i);
					stringArrayList11.add(e.getString("id"));
					stringArrayList12.add(e.getString("name"));

				}
				selectid = stringArrayList11
						.toArray(new String[stringArrayList11.size()]);
				selectname = stringArrayList12
						.toArray(new String[stringArrayList12.size()]);
			} catch (JSONException e) {
				System.out.println(e);
				Log.e("log_tag", "Error parsing data " + e.toString());
			}

		} else {

			Toast.makeText(getApplicationContext(), "No Internet Connection",
					Toast.LENGTH_LONG).show();
		}
*/
	}

	protected void detail() {
		/*
		boolean answer;
		answer = isOnline();
		System.out.println(answer);
		stringArrayList1 = new ArrayList<String>();
		stringArrayList2 = new ArrayList<String>();
		stringArrayList3 = new ArrayList<String>();

		if (answer) {

			JSONObject json = JSONfunctions.getJSONfromURL(Global.detail_url);
			try {
				JSONObject response1 = json.getJSONObject("response");
				response1.toString();
				JSONArray data = response1.getJSONArray("items");

				for (int i = 0; i < data.length(); i++) {

					JSONObject e = data.getJSONObject(i);
					stringArrayList1.add(e.getString("district"));
					stringArrayList2.add(e.getString("sub_district"));
					stringArrayList3.add(e.getString("desa"));

				}
				select_district = stringArrayList1
						.toArray(new String[stringArrayList1.size()]);
				select_sub = stringArrayList2
						.toArray(new String[stringArrayList2.size()]);
				select_desa = stringArrayList3
						.toArray(new String[stringArrayList3.size()]);
			} catch (JSONException e) {
				System.out.println(e);
				Log.e("log_tag", "Error parsing data " + e.toString());
			}

		} else {

			Toast.makeText(getApplicationContext(), "No Internet Connection",
					Toast.LENGTH_LONG).show();
		}
		*/

	}

	public boolean isOnline() {
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm.getActiveNetworkInfo();
		if (netInfo != null && netInfo.isConnectedOrConnecting()) {
			return true;
		}
		return false;
	}

	class Check extends AsyncTask {
		//

		private String json;
		private JSONObject jsonobject;
		private String code;
		private String msg;
		private String url;
		private Dialog dialog;

		/*
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			dialog = new Dialog(Dering_Pengelola_1.this);
			dialog.setTitle("Loading...");
			dialog.setCancelable(false);
			dialog.show();

		}
		*/

		@Override
		protected Object doInBackground(Object... params) {

			try {
				province();
				detail();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}

		@Override
		protected void onPostExecute(Object result) {
/*
			if (selectname.length > 0) {
			//	ArrayAdapter adapter = new ArrayAdapter(
			//			Dering_Pengelola_1.this,
			//			android.R.layout.simple_spinner_item, selectname);
				//s.setAdapter(adapter);
			}
			if (select_district.length > 0) {
			//	ArrayAdapter adapter1 = new ArrayAdapter(
			//			Dering_Pengelola_1.this,
			//			android.R.layout.simple_spinner_item, select_district);
				//s1.setAdapter(adapter1);
			}
			if (select_sub.length > 0) {
			//	ArrayAdapter adapter2 = new ArrayAdapter(
			//			Dering_Pengelola_1.this,
			//			android.R.layout.simple_spinner_item, select_sub);
				//s2.setAdapter(adapter2);
			}
			if (select_desa.length > 0) {
			//	ArrayAdapter adapter3 = new ArrayAdapter(
			//			Dering_Pengelola_1.this,
			//			android.R.layout.simple_spinner_item, select_desa);
				//s3.setAdapter(adapter3);
			}

			dialog.dismiss();
*/
		}

	}
}
